package com.zzzy.cont.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzzy.common.util.MyBatisUtils;
import com.zzzy.common.vo.PageResult;
import com.zzzy.cont.dao.entity.Contract;
import com.zzzy.cont.vo.contract.dept.DeptConPageReq;
import com.zzzy.framework.common.enums.sys.DataScopeEnum;
import com.zzzy.framework.common.util.SecurityUtils;
import com.zzzy.framework.common.util.SortFieldUtil;
import com.zzzy.framework.dto.DataPermissionDto;
import org.springframework.stereotype.Service;

@Service
public class DeptConService extends ConService {
    public PageResult<Contract> getDeptConPage(DeptConPageReq queryReq) {
        DataPermissionDto dataPermissionDto = SecurityUtils.getLoginUser().getDataPermissionDto();
        if (DataScopeEnum.SELF.getValue().equals(dataPermissionDto.getDataPermission())){
            return new PageResult<>();
        }
        IPage<Contract> mpPage = MyBatisUtils.buildPage(queryReq, SortFieldUtil.getSortingFields(Contract.class, queryReq.getOrderField(), queryReq.getOrderRule()));
        if (DataScopeEnum.ALL.getValue().equals(dataPermissionDto.getDataPermission())){
            mpPage = baseMapper.selectAllDeptConPage(mpPage, queryReq);
        } else {
            mpPage = baseMapper.selectDeptConPage(mpPage, queryReq, dataPermissionDto.getUserIdSet());
        }
        return new PageResult<>(mpPage);
    }

}
